require.config({
    paths: {
        'vue': '../encaptool/encvue',
        'iview': '../utiltool/iview/iview',
        'jquery': '../utiltool/jquery/jquery.min',
        'router': '../encaptool/encarouter',
        'axios': '../encaptool/encaxios'
    },
    shim: {
        iview: [
            'vue'
        ]
    }
})
require(['vue', 'iview', 'jquery', 'router', 'axios'], function(Vue, iview, $, Router, axios) {
    Vue.use(iview);
    new Vue({
        el: '#app',
        data() {
            return {
                isCollapsed: false,
                router: new Router,
                catalogMap: {
                    targeturl: '/YF/public/pages/map',
                    showurl: '#/main/map',
                    name: '监控视图'
                },
                completed: {
                    targeturl: '/YF/public/pages/completed',
                    showurl: '#/main/completed',
                    name: '已完成送货单'
                },
                setting: {
                    method: "GET",
                    url: '/YF/public/static/config.json'
                },
                itemlist:[]
            };
        },
        mounted() {
            this.getconfig();
        },
        methods: {
            handlerouter: function(routerobj, router) {
                var content = $('#js_main');
                router.route(routerobj.showurl.replace('#', ''), function() {
                    this.loadpage(content, routerobj.targeturl, axios);
                }.bind(this));
            },
            getconfig(){
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        this.itemlist = res.data;
                        var router = this.router;
                        router.init();
                        for(var o in this.itemlist)
                        {
                           this.handlerouter(this.itemlist[o],router);
                        }
                        var url = location.hash.slice(1);
                        if (url.trim()) {
                            router._gopage(url);
                        } else {
                            location.href =  this.itemlist[0].showurl;
                        }
                    } else {
                        this.$Message.error("未查到数据");
                    }
                }.bind(this), {
                    setting: this.setting
                });
            }
        },
        computed: {
            menuitemClasses: function() {
                return [
                    'menu-item',
                    this.isCollapsed ? 'collapsed-menu' : ''
                ]
            }
        }
    })
})